export const getFileUrl = name => {
  const url = new URL(`../../assets/${name}`, import.meta.url).href
  return url
}

// 序号
export const getSerialNo = (index = 0) => {
  return (index + 1).toString().padStart(2, '0')
}

// 获取图表缩放范围比例
export const getEchartsZoomEnd = (list = [], num = 7) => {
  if (!(list && Array.isArray(list) && list.length && num && Number(num))) {
    return {
      zoomShow: false,
      zoomEnd: 100,
    }
  }

  const len = list.length || 0,
    zoomShow = len > num,
    zoomEnd = zoomShow ? ((num / len) * 100).toFixed(2) : 100

  return {
    zoomShow,
    zoomEnd,
  }
}

// 获取图表x轴label
export const getEchartsXAxisLabel = (label = '', num = 2) => {
  const len = label.length

  if (len < num) {
    return label
  } else {
    const strA = label.slice(0, num),
      strB = label.slice(num, num * 2),
      str = `${strA}\n${strB}`

    return str
  }
}
